<script setup>
import { useI18n } from "vue-i18n";
import { getBrowserLang } from "@/utils";
import en from "element-plus/es/locale/lang/en";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import { useAppStore } from "@/stores/modules/desktop.js";

const appStore = useAppStore();
// init language
const i18n = useI18n();
onMounted(() => {
  const language = appStore.language ?? getBrowserLang();
  i18n.locale.value = language;
  appStore.setAppState("language", language);
});
// element assemblySize
const size = computed(() => appStore.assemblySize);
// element language
const locale = computed(() => {
  if (appStore.language === "zh") return zhCn;
  if (appStore.language === "en") return en;
  return getBrowserLang() === "zh" ? zhCn : en;
});
</script>

<template>
  <el-config-provider :locale="locale" :size="size">
    <router-view />
  </el-config-provider>
</template>
